package com.atguigu.springboot.component;/*
代码的功能：
@author:
@return:
@throws:
@args:
实现在链接上携带区域信息
*/

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class MyLocalResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        Locale local = Locale.getDefault();
        String l = request.getParameter("l");
        if (!(StringUtils.isEmpty(l))){
            String[] s = l.split("_");
            local = new Locale(s[0], s[1]);
        }
        return local;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
